home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / mysql / scripts / mysqld_multi < prev    next >
Text File  |  2005-04-01  |  22KB  |  784 lines

  1. #!/usr/bin/perl
  2.  
  3. use Getopt::Long;
  4. use POSIX qw(strftime);
  5.  
  6. $|=1;
  7. $VER="2.11";
  8.  
  9. $opt_config_file   = undef();
  10. $opt_example       = 0;
  11. $opt_help          = 0;
  12. $opt_log           = undef();
  13. $opt_mysqladmin    = "/usr/local/bin/mysqladmin";
  14. $opt_mysqld        = "/usr/local/libexec/mysqld";
  15. $opt_no_log        = 0;
  16. $opt_password      = undef();
  17. $opt_tcp_ip        = 0;
  18. $opt_user          = "root";
  19. $opt_version       = 0;
  20. $opt_silent        = 0;
  21. $opt_verbose       = 0;
  22.  
  23. my $my_print_defaults_exists= 1;
  24. my $logdir= undef();
  25.  
  26. my ($mysqld, $mysqladmin, $groupids, $homedir, $my_progname);
  27.  
  28. $homedir = $ENV{HOME};
  29. $my_progname = $0;
  30. $my_progname =~ s/.*[\/]//;
  31.  
  32. main();
  33.  
  34. ####
  35. #### main sub routine
  36. ####
  37.  
  38. sub main
  39. {
  40.   my ($flag_exit);
  41.  
  42.   if (!defined(my_which(my_print_defaults)))
  43.   {
  44.     # We can't throw out yet, since --version, --help, or --example may
  45.     # have been given
  46.     print "WARNING! my_print_defaults command not found!\n";
  47.     print "Please make sure you have this command available and\n";
  48.     print "in your path. The command is available from the latest\n";
  49.     print "MySQL distribution.\n";
  50.     $my_print_defaults_exists= 0;
  51.   }
  52.   if ($my_print_defaults_exists)
  53.   {
  54.     foreach my $arg (@ARGV)
  55.     {
  56.       if ($arg =~ m/^--config-file=(.*)/)
  57.       {
  58.     if (!length($1))
  59.     {
  60.       die "Option config-file requires an argument\n";
  61.     }
  62.     elsif (!( -e $1 && -r $1))
  63.     {
  64.       die "Option file '$1' doesn't exists, or is not readable\n";
  65.     }
  66.     else
  67.     {
  68.       $opt_config_file= $1;
  69.     }
  70.       }
  71.     }
  72.     my $com= "my_print_defaults ";
  73.     $com.= "--config-file=$opt_config_file " if (defined($opt_config_file));
  74.     $com.= "mysqld_multi";
  75.     my @defops = `$com`;
  76.     chop @defops;
  77.     splice @ARGV, 0, 0, @defops;
  78.   }
  79.   GetOptions("help","example","version","mysqld=s","mysqladmin=s",
  80.              "config-file=s","user=s","password=s","log=s","no-log","tcp-ip",
  81.              "silent","verbose")
  82.   || die "Wrong option! See $my_progname --help for detailed information!\n";
  83.  
  84.   if ($opt_verbose && $opt_silent)
  85.   {
  86.     print "Both --verbose and --silent has been given. Some of the warnings ";
  87.     print "will be disabled\nand some will be enabled.\n\n";
  88.   }
  89.  
  90.   init_log() if (!defined($opt_log));
  91.   $groupids = $ARGV[1];
  92.   if ($opt_version)
  93.   {
  94.     print "$my_progname version $VER by Jani Tolonen\n";
  95.     exit(0);
  96.   }
  97.   example() if ($opt_example);
  98.   usage() if ($opt_help);
  99.   if ($flag_exit)
  100.   {
  101.     print "Error with an option, see $my_progname --help for more info!\n";
  102.     exit(1);
  103.   }
  104.   if (!defined(my_which(my_print_defaults)))
  105.   {
  106.     print "ABORT: Can't find command 'my_print_defaults'!\n";
  107.     print "This command is available from the latest MySQL\n";
  108.     print "distribution. Please make sure you have the command\n";
  109.     print "in your PATH.\n";
  110.     exit(1);
  111.   }
  112.   usage() if (!defined($ARGV[0]) ||
  113.           (!($ARGV[0] =~ m/^start$/i) &&
  114.            !($ARGV[0] =~ m/^stop$/i) &&
  115.            !($ARGV[0] =~ m/^report$/i)));
  116.  
  117.   if (!$opt_no_log)
  118.   {
  119.     w2log("$my_progname log file version $VER; run: ",
  120.       "$opt_log", 1, 0);
  121.   }
  122.   else
  123.   {
  124.     print "$my_progname log file version $VER; run: ";
  125.     print strftime "%a %b %e %H:%M:%S %Y", localtime;
  126.     print "\n";
  127.   }
  128.   if ($ARGV[0] =~ m/^start$/i)
  129.   {
  130.     if (!defined(($mysqld= my_which($opt_mysqld))) && $opt_verbose)
  131.     {
  132.       print "WARNING: Couldn't find the default mysqld binary.\n";
  133.       print "Tried: $opt_mysqld\n";
  134.       print "This is OK, if you are using option \"mysqld=...\" in ";
  135.       print "groups [mysqldN] separately for each.\n\n";
  136.     }
  137.     start_mysqlds();
  138.   }
  139.   else
  140.   {
  141.     if (!defined(($mysqladmin= my_which($opt_mysqladmin))) && $opt_verbose)
  142.     {
  143.       print "WARNING: Couldn't find the default mysqladmin binary.\n";
  144.       print "Tried: $opt_mysqladmin\n";
  145.       print "This is OK, if you are using option \"mysqladmin=...\" in ";
  146.       print "groups [mysqldN] separately for each.\n\n";
  147.     }
  148.     if ($ARGV[0] =~ m/^report$/i)
  149.     {
  150.       report_mysqlds();
  151.     }
  152.     else
  153.     {
  154.       stop_mysqlds();
  155.     }
  156.   }
  157. }
  158.  
  159. ####
  160. #### Init log file. Check for appropriate place for log file, in the following
  161. #### order my_print_defaults mysqld datadir, /usr/local/share, /var/log, /tmp
  162. ####
  163.  
  164. sub init_log
  165. {
  166.   if ($my_print_defaults_exists)
  167.   {
  168.     @mysqld_opts= `my_print_defaults mysqld`;
  169.     chomp @mysqld_opts;
  170.     foreach my $opt (@mysqld_opts)
  171.     {
  172.       if ($opt =~ m/^\-\-datadir[=](.*)/)
  173.       {
  174.         if (-d "$1" && -w "$1")
  175.         {
  176.       $logdir= $1;
  177.         }
  178.       }
  179.     }
  180.   }
  181.   if (!defined($logdir))
  182.   {
  183.     $logdir= "/usr/local/share" if (-d "/usr/local/share" && -w "/usr/local/share");
  184.   }
  185.   if (!defined($logdir))
  186.   {
  187.     # Log file was not specified and we could not log to a standard place,
  188.     # so log file be disabled for now.
  189.     if (!$opt_silent)
  190.     {
  191.       print "WARNING: Log file disabled. Maybe directory or file isn't writable?\n";
  192.     }
  193.     $opt_no_log= 1;
  194.   }
  195.   else
  196.   {
  197.     $opt_log= "$logdir/mysqld_multi.log";
  198.   }
  199. }
  200.  
  201. ####
  202. #### Report living and not running MySQL servers
  203. ####
  204.  
  205. sub report_mysqlds
  206. {
  207.   my (@groups, $com, $i, @options, $pec);
  208.  
  209.   print "Reporting MySQL servers\n";
  210.   if (!$opt_no_log)
  211.   {
  212.     w2log("\nReporting MySQL servers","$opt_log",0,0);
  213.   }
  214.   @groups = &find_groups($groupids);
  215.   for ($i = 0; defined($groups[$i]); $i++)
  216.   {
  217.     $com= get_mysqladmin_options($i, @groups);
  218.     $com.= " ping >> /dev/null 2>&1";
  219.     system($com);
  220.     $pec = $? >> 8;
  221.     if ($pec)
  222.     {
  223.       print "MySQL server from group: $groups[$i] is not running\n";
  224.       if (!$opt_no_log)
  225.       {
  226.     w2log("MySQL server from group: $groups[$i] is not running",
  227.           "$opt_log", 0, 0);
  228.       }
  229.     }
  230.     else
  231.     {
  232.       print "MySQL server from group: $groups[$i] is running\n";
  233.       if (!$opt_no_log)
  234.       {
  235.     w2log("MySQL server from group: $groups[$i] is running",
  236.           "$opt_log", 0, 0);
  237.       }
  238.     }
  239.   }
  240.   if (!$i)
  241.   {
  242.     print "No groups to be reported (check your GNRs)\n";
  243.     if (!$opt_no_log)
  244.     {
  245.       w2log("No groups to be reported (check your GNRs)", "$opt_log", 0, 0);
  246.     }
  247.   }
  248. }
  249.  
  250. ####
  251. #### start multiple servers
  252. ####
  253.  
  254. sub start_mysqlds()
  255. {
  256.   my (@groups, $com, $tmp, $i, @options, $j, $mysqld_found, $info_sent);
  257.  
  258.   if (!$opt_no_log)
  259.   {
  260.     w2log("\nStarting MySQL servers\n","$opt_log",0,0);
  261.   }
  262.   else
  263.   {
  264.     print "\nStarting MySQL servers\n";
  265.   }
  266.   @groups = &find_groups($groupids);
  267.   for ($i = 0; defined($groups[$i]); $i++)
  268.   {
  269.     $com = "my_print_defaults";
  270.     $com.= defined($opt_config_file) ? " --config-file=$opt_config_file" : "";
  271.     $com.= " $groups[$i]";
  272.     @options = `$com`;
  273.     chop @options;
  274.  
  275.     $mysqld_found= 1; # The default
  276.     $mysqld_found= 0 if (!length($mysqld));
  277.     $com= "$mysqld";
  278.     for ($j = 0, $tmp= ""; defined($options[$j]); $j++)
  279.     {
  280.       if ("--mysqladmin=" eq substr($options[$j], 0, 13))
  281.       {
  282.     # catch this and ignore
  283.       }
  284.       elsif ("--mysqld=" eq substr($options[$j], 0, 9))
  285.       {
  286.     $options[$j]=~ s/\-\-mysqld\=//;
  287.     $com= $options[$j];
  288.         $mysqld_found= 1;
  289.       }
  290.       else
  291.       {
  292.     $options[$j]=~ s/;/\\;/g;
  293.     $tmp.= " $options[$j]";
  294.       }
  295.     }
  296.     if ($opt_verbose && $com =~ m/\/safe_mysqld$/ && !$info_sent)
  297.     {
  298.       print "WARNING: safe_mysqld is being used to start mysqld. In this case you ";
  299.       print "may need to pass\n\"ledir=...\" under groups [mysqldN] to ";
  300.       print "safe_mysqld in order to find the actual mysqld binary.\n";
  301.       print "ledir (library executable directory) should be the path to the ";
  302.       print "wanted mysqld binary.\n\n";
  303.       $info_sent= 1;
  304.     }
  305.     $com.= $tmp;
  306.     $com.= " >> $opt_log 2>&1" if (!$opt_no_log);
  307.     $com.= " &";
  308.     if (!$mysqld_found)
  309.     {
  310.       print "\n";
  311.       print "FATAL ERROR: Tried to start mysqld under group [$groups[$i]], ";
  312.       print "but no mysqld binary was found.\n";
  313.       print "Please add \"mysqld=...\" in group [mysqld_multi], or add it to ";
  314.       print "group [$groups[$i]] separately.\n";
  315.       exit(1);
  316.     }
  317.     system($com);
  318.   }
  319.   if (!$i && !$opt_no_log)
  320.   {
  321.     w2log("No MySQL servers to be started (check your GNRs)",
  322.       "$opt_log", 0, 0);
  323.   }
  324. }
  325.  
  326. ####
  327. #### stop multiple servers
  328. ####
  329.  
  330. sub stop_mysqlds()
  331. {
  332.   my (@groups, $com, $i, @options);
  333.  
  334.   if (!$opt_no_log)
  335.   {
  336.     w2log("\nStopping MySQL servers\n","$opt_log",0,0);
  337.   }
  338.   else
  339.   {
  340.     print "\nStopping MySQL servers\n";
  341.   }
  342.   @groups = &find_groups($groupids);
  343.   for ($i = 0; defined($groups[$i]); $i++)
  344.   {
  345.     $com= get_mysqladmin_options($i, @groups);
  346.     $com.= " shutdown";
  347.     $com.= " >> $opt_log 2>&1" if (!$opt_no_log);
  348.     $com.= " &";
  349.     system($com);
  350.   }
  351.   if (!$i && !$opt_no_log)
  352.   {
  353.     w2log("No MySQL servers to be stopped (check your GNRs)",
  354.       "$opt_log", 0, 0);
  355.   }
  356. }
  357.  
  358. ####
  359. #### Sub function for mysqladmin option parsing
  360. ####
  361.  
  362. sub get_mysqladmin_options
  363. {
  364.   my ($i, @groups)= @_;
  365.   my ($mysqladmin_found, $com, $tmp, $j);
  366.  
  367.   $com = "my_print_defaults";
  368.   $com.= defined($opt_config_file) ? " --config-file=$opt_config_file" : "";
  369.   $com.= " $groups[$i]";
  370.   @options = `$com`;
  371.   chop @options;
  372.  
  373.   $mysqladmin_found= 1; # The default
  374.   $mysqladmin_found= 0 if (!length($mysqladmin));
  375.   $com = "$mysqladmin";
  376.   $tmp = " -u $opt_user";
  377.   $tmp.= defined($opt_password) ? " -p$opt_password" : "";
  378.   $tmp.= $opt_tcp_ip ? " -h 127.0.0.1" : "";
  379.   for ($j = 0; defined($options[$j]); $j++)
  380.   {
  381.     if ("--mysqladmin=" eq substr($options[$j], 0, 13))
  382.     {
  383.       $options[$j]=~ s/\-\-mysqladmin\=//;
  384.       $com= $options[$j];
  385.       $mysqladmin_found= 1;
  386.     }
  387.     elsif ((($options[$j] =~ m/^(\-\-socket\=)(.*)$/) && !$opt_tcp_ip) ||
  388.        ($options[$j] =~ m/^(\-\-port\=)(.*)$/))
  389.     {
  390.       $tmp.= " $options[$j]";
  391.     }
  392.   }
  393.   if (!$mysqladmin_found)
  394.   {
  395.     print "\n";
  396.     print "FATAL ERROR: Tried to use mysqladmin in group [$groups[$i]], ";
  397.     print "but no mysqladmin binary was found.\n";
  398.     print "Please add \"mysqladmin=...\" in group [mysqld_multi], or ";
  399.     print "in group [$groups[$i]].\n";
  400.     exit(1);
  401.   }
  402.   $com.= $tmp;
  403.   return $com;
  404. }
  405.  
  406. ####
  407. #### Find groups. Takes the valid group numbers as an argument, parses
  408. #### them, puts them in the ascending order, removes duplicates and
  409. #### returns the wanted groups accordingly.
  410. ####
  411.  
  412. sub find_groups
  413. {
  414.   my ($raw_gids) = @_;
  415.   my (@groups, @data, @tmp, $line, $i, $k, @pre_gids, @gids, @tmp2,
  416.       $prev_value);
  417.  
  418.   # Read the lines from the config file to variable 'data'
  419.   if (defined($opt_config_file))
  420.   {
  421.     open(MY_CNF, "<$opt_config_file") && (@data=<MY_CNF>) && close(MY_CNF);
  422.   }
  423.   else
  424.   {
  425.     if (-f "/etc/my.cnf" && -r "/etc/my.cnf")
  426.     {
  427.       open(MY_CNF, "</etc/my.cnf") && (@tmp=<MY_CNF>) && close(MY_CNF);
  428.     }
  429.     for ($i = 0; ($line = shift @tmp); $i++)
  430.     {
  431.       $data[$i] = $line;
  432.     }
  433.     if (-f "$homedir/.my.cnf" && -r "$homedir/.my.cnf")
  434.     {
  435.       open(MY_CNF, "<$homedir/.my.cnf") && (@tmp=<MY_CNF>) && close(MY_CNF);
  436.     }
  437.     for (; ($line = shift @tmp); $i++)
  438.     {
  439.       $data[$i] = $line;
  440.     }
  441.   }
  442.   chop @data;
  443.   # Make a list of the wanted group ids
  444.   if (defined($raw_gids))
  445.   {
  446.     @pre_gids = split(',', $raw_gids);
  447.   }
  448.   if (defined($raw_gids))
  449.   {
  450.     for ($i = 0, $j = 0; defined($pre_gids[$i]); $i++)
  451.     {
  452.       if ($pre_gids[$i] =~ m/^(\d+)$/)
  453.       {
  454.     $gids[$j] = $1;
  455.     $j++;
  456.       }
  457.       elsif ($pre_gids[$i] =~ m/^(\d+)(\-)(\d+)$/)
  458.       {
  459.     for ($k = $1; $k <= $3; $k++)
  460.     {
  461.       $gids[$j] = $k;
  462.       $j++;
  463.     }
  464.       }
  465.       else
  466.       {
  467.     print "ABORT: Bad GNR: $pre_gids[$i] See $my_progname --help\n";
  468.     exit(1);
  469.       }
  470.     }
  471.   }
  472.   # Sort the list of gids numerically in ascending order
  473.   @gids = sort {$a <=> $b} @gids;
  474.   # Remove non-positive integers and duplicates
  475.   for ($i = 0, $j = 0; defined($gids[$i]); $i++)
  476.   {
  477.     next if ($gids[$i] <= 0);
  478.     if (!$i || $prev_value != $gids[$i])
  479.     {
  480.       $tmp2[$j] = $gids[$i];
  481.       $j++;
  482.     }
  483.     $prev_value = $gids[$i];
  484.   }
  485.   @gids = @tmp2;
  486.   # Find and return the wanted groups
  487.   for ($i = 0, $j = 0; defined($data[$i]); $i++)
  488.   {
  489.     if ($data[$i] =~ m/^(\s*\[\s*)(mysqld)(\d+)(\s*\]\s*)$/)
  490.     {
  491.       if (defined($raw_gids))
  492.       {
  493.     for ($k = 0; defined($gids[$k]); $k++)
  494.     {
  495.       if ($gids[$k] == $3)
  496.       {
  497.         $groups[$j] = $2 . $3;
  498.         $j++;
  499.       }
  500.     }
  501.       }
  502.       else
  503.       {
  504.     $groups[$j] = $2 . $3;
  505.     $j++;
  506.       }
  507.     }
  508.   }
  509.   return @groups;
  510. }
  511.  
  512. ####
  513. #### w2log: Write to a logfile.
  514. #### 1.arg: append to the log file (given string, or from a file. if a file,
  515. ####        file will be read from $opt_logdir)
  516. #### 2.arg: logfile -name (w2log assumes that the logfile is in $opt_logdir).
  517. #### 3.arg. 0 | 1, if true, print current date to the logfile. 3. arg will
  518. ####        be ignored, if 1. arg is a file.
  519. #### 4.arg. 0 | 1, if true, first argument is a file, else a string
  520. ####
  521.  
  522. sub w2log
  523. {
  524.   my ($msg, $file, $date_flag, $is_file)= @_;
  525.   my (@data);
  526.  
  527.   open (LOGFILE, ">>$opt_log")
  528.     or die "FATAL: w2log: Couldn't open log file: $opt_log\n";
  529.  
  530.   if ($is_file)
  531.   {
  532.     open (FROMFILE, "<$msg") && (@data=<FROMFILE>) &&
  533.       close(FROMFILE)
  534.     or die "FATAL: w2log: Couldn't open file: $msg\n";
  535.     foreach my $line (@data)
  536.     {
  537.       print LOGFILE "$line";
  538.     }
  539.   }
  540.   else
  541.   {
  542.     print LOGFILE "$msg";
  543.     print LOGFILE strftime "%a %b %e %H:%M:%S %Y", localtime if ($date_flag);
  544.     print LOGFILE "\n";
  545.   }
  546.   close (LOGFILE);
  547.   return;
  548. }
  549.  
  550. ####
  551. #### my_which is used, because we can't assume that every system has the
  552. #### which -command. my_which can take only one argument at a time.
  553. #### Return values: requested system command with the first found path,
  554. #### or undefined, if not found.
  555. ####
  556.  
  557. sub my_which
  558. {
  559.   my ($command) = @_;
  560.   my (@paths, $path);
  561.  
  562.   return $command if (-f $command && -x $command);
  563.   @paths = split(':', $ENV{'PATH'});
  564.   foreach $path (@paths)
  565.   {
  566.     $path .= "/$command";
  567.     return $path if (-f $path && -x $path);
  568.   }
  569.   return undef();
  570. }
  571.  
  572.  
  573. ####
  574. #### example
  575. ####
  576.  
  577. sub example
  578. {
  579.   print <<EOF;
  580. # This is an example of a my.cnf file for $my_progname.
  581. # Usually this file is located in home dir ~/.my.cnf or /etc/my.cnf
  582. #
  583. # SOME IMPORTANT NOTES FOLLOW:
  584. #
  585. # 1.COMMON USER
  586. #
  587. #   Make sure that the MySQL user, who is stopping the mysqld services, has
  588. #   the same password to all MySQL servers being accessed by $my_progname.
  589. #   This user needs to have the 'Shutdown_priv' -privilege, but for security
  590. #   reasons should have no other privileges. It is advised that you create a
  591. #   common 'multi_admin' user for all MySQL servers being controlled by
  592. #   $my_progname. Here is an example how to do it:
  593. #
  594. #   GRANT SHUTDOWN ON *.* TO multi_admin\@localhost IDENTIFIED BY 'password'
  595. #
  596. #   You will need to apply the above to all MySQL servers that are being
  597. #   controlled by $my_progname. 'multi_admin' will shutdown the servers
  598. #   using 'mysqladmin' -binary, when '$my_progname stop' is being called.
  599. #
  600. # 2.PID-FILE
  601. #
  602. #   If you are using mysqld_safe to start mysqld, make sure that every
  603. #   MySQL server has a separate pid-file. In order to use mysqld_safe
  604. #   via $my_progname, you need to use two options:
  605. #
  606. #   mysqld=/path/to/mysqld_safe
  607. #   ledir=/path/to/mysqld-binary/
  608. #
  609. #   ledir (library executable directory), is an option that only mysqld_safe
  610. #   accepts, so you will get an error if you try to pass it to mysqld directly.
  611. #   For this reason you might want to use the above options within [mysqld#]
  612. #   group directly.
  613. #
  614. # 3.DATA DIRECTORY
  615. #
  616. #   It is NOT advised to run many MySQL servers within the same data directory.
  617. #   You can do so, but please make sure to understand and deal with the
  618. #   underlying caveats. In short they are:
  619. #   - Speed penalty
  620. #   - Risk of table/data corruption
  621. #   - Data synchronising problems between the running servers
  622. #   - Heavily media (disk) bound
  623. #   - Relies on the system (external) file locking
  624. #   - Is not applicable with all table types. (Such as InnoDB)
  625. #     Trying so will end up with undesirable results.
  626. #
  627. # 4.TCP/IP Port
  628. #
  629. #   Every server requires one and it must be unique.
  630. #
  631. # 5.[mysqld#] Groups
  632. #
  633. #   In the example below the first and the fifth mysqld group was
  634. #   intentionally left out. You may have 'gaps' in the config file. This
  635. #   gives you more flexibility.
  636. #
  637. # 6.MySQL Server User
  638. #
  639. #   You can pass the user=... option inside [mysqld#] groups. This
  640. #   can be very handy in some cases, but then you need to run $my_progname
  641. #   as UNIX root.
  642. #
  643. # 7.A Start-up Manage Script for $my_progname
  644. #
  645. #   In the recent MySQL distributions you can find a file called
  646. #   mysqld_multi.server.sh. It is a wrapper for $my_progname. This can
  647. #   be used to start and stop multiple servers during boot and shutdown.
  648. #
  649. #   You can place the file in /etc/init.d/mysqld_multi.server.sh and
  650. #   make the needed symbolic links to it from various run levels
  651. #   (as per Linux/Unix standard). You may even replace the
  652. #   /etc/init.d/mysql.server script with it.
  653. #
  654. #   Before using, you must create a my.cnf file either in /etc/my.cnf
  655. #   or /root/.my.cnf and add the [mysqld_multi] and [mysqld#] groups.
  656. #
  657. #   The script can be found from support-files/mysqld_multi.server.sh
  658. #   in MySQL distribution. (Verify the script before using)
  659. #
  660.  
  661. [mysqld_multi]
  662. mysqld     = /usr/local/bin/mysqld_safe
  663. mysqladmin = /usr/local/bin/mysqladmin
  664. user       = multi_admin
  665. password   = my_password
  666.  
  667. [mysqld2]
  668. socket     = /tmp/mysql.sock2
  669. port       = 3307
  670. pid-file   = /usr/local/var2/hostname.pid2
  671. datadir    = /usr/local/var2
  672. language   = /usr/local/share/mysql/english
  673. user       = unix_user1
  674.  
  675. [mysqld3]
  676. mysqld     = /path/to/safe_mysqld/safe_mysqld
  677. ledir      = /path/to/mysqld-binary/
  678. mysqladmin = /path/to/mysqladmin/mysqladmin
  679. socket     = /tmp/mysql.sock3
  680. port       = 3308
  681. pid-file   = /usr/local/var3/hostname.pid3
  682. datadir    = /usr/local/var3
  683. language   = /usr/local/share/mysql/swedish
  684. user       = unix_user2
  685.  
  686. [mysqld4]
  687. socket     = /tmp/mysql.sock4
  688. port       = 3309
  689. pid-file   = /usr/local/var4/hostname.pid4
  690. datadir    = /usr/local/var4
  691. language   = /usr/local/share/mysql/estonia
  692. user       = unix_user3
  693.  
  694. [mysqld6]
  695. socket     = /tmp/mysql.sock6
  696. port       = 3311
  697. pid-file   = /usr/local/var6/hostname.pid6
  698. datadir    = /usr/local/var6
  699. language   = /usr/local/share/mysql/japanese
  700. user       = unix_user4
  701. EOF
  702.   exit(0);
  703. }
  704.  
  705. ####
  706. #### usage
  707. ####
  708.  
  709. sub usage
  710. {
  711.   print <<EOF;
  712. $my_progname version $VER by Jani Tolonen
  713.  
  714. This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  715. and you are welcome to modify and redistribute it under the GPL license.
  716.  
  717. Description:
  718. $my_progname can be used to start, or stop any number of separate
  719. mysqld processes running in different TCP/IP ports and UNIX sockets.
  720.  
  721. $my_progname can read group [mysqld_multi] from my.cnf file. You may
  722. want to put options mysqld=... and mysqladmin=... there.  Since
  723. version 2.10 these options can also be given under groups [mysqld#],
  724. which gives more control over different versions.  One can have the
  725. default mysqld and mysqladmin under group [mysqld_multi], but this is
  726. not mandatory. Please note that if mysqld or mysqladmin is missing
  727. from both [mysqld_multi] and [mysqld#], a group that is tried to be
  728. used, $my_progname will abort with an error.
  729.  
  730. $my_progname will search for groups named [mysqld#] from my.cnf (or
  731. the given --config-file=...), where '#' can be any positive integer
  732. starting from 1. These groups should be the same as the regular
  733. [mysqld] group, but with those port, socket and any other options
  734. that are to be used with each separate mysqld process. The number
  735. in the group name has another function; it can be used for starting,
  736. stopping, or reporting any specific mysqld server.
  737.  
  738. Usage: $my_progname [OPTIONS] {start|stop|report} [GNR,GNR,GNR...]
  739. or     $my_progname [OPTIONS] {start|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
  740.  
  741. The GNR means the group number. You can start, stop or report any GNR,
  742. or several of them at the same time. (See --example) The GNRs list can
  743. be comma separated or a dash combined. The latter means that all the
  744. GNRs between GNR1-GNR2 will be affected. Without GNR argument all the
  745. groups found will either be started, stopped, or reported. Note that
  746. syntax for specifying GNRs must appear without spaces.
  747.  
  748. Options:
  749. --config-file=...  Alternative config file.
  750.                    Using: $opt_config_file
  751. --example          Give an example of a config file with extra information.
  752. --help             Print this help and exit.
  753. --log=...          Log file. Full path to and the name for the log file. NOTE:
  754.                    If the file exists, everything will be appended.
  755.                    Using: $opt_log
  756. --mysqladmin=...   mysqladmin binary to be used for a server shutdown.
  757.                    Since version 2.10 this can be given within groups [mysqld#]
  758.                    Using: $mysqladmin
  759. --mysqld=...       mysqld binary to be used. Note that you can give mysqld_safe
  760.                    to this option also. The options are passed to mysqld. Just
  761.                    make sure you have mysqld in your PATH or fix mysqld_safe.
  762.                    Using: $mysqld
  763.                    Please note: Since mysqld_multi version 2.3 you can also
  764.                    give this option inside groups [mysqld#] in ~/.my.cnf,
  765.                    where '#' stands for an integer (number) of the group in
  766.                    question. This will be recognised as a special option and
  767.                    will not be passed to the mysqld. This will allow one to
  768.                    start different mysqld versions with mysqld_multi.
  769. --no-log           Print to stdout instead of the log file. By default the log
  770.                    file is turned on.
  771. --password=...     Password for mysqladmin user.
  772. --silent           Disable warnings.
  773. --tcp-ip           Connect to the MySQL server(s) via the TCP/IP port instead
  774.                    of the UNIX socket. This affects stopping and reporting.
  775.                    If a socket file is missing, the server may still be
  776.                    running, but can be accessed only via the TCP/IP port.
  777.                    By default connecting is done via the UNIX socket.
  778. --user=...         mysqladmin user. Using: $opt_user
  779. --verbose          Be more verbose.
  780. --version          Print the version number and exit.
  781. EOF
  782.   exit(0);
  783. }
  784.